﻿/*
    a06_Struct @ https://gitee.com/zcatt/MyDemo2020
struct是值类型, 再stack上分配. 因其是值类型, 所以再一般参数传递中是值传递.
 */ 
using System;
using System.Security.Cryptography.X509Certificates;

struct MyStruct
{
    int m_value;

    public int X
    {
        get
        {
            return m_value;
        }

        set
        {
            m_value = value;
        }
    }

    public void showX()
    {
        Console.WriteLine("X=" + X);
    }
}

class MyClass
{
    int m_value;
    public int X
    {
        get
        {
            return m_value;
        }

        set
        {
            m_value = value;
        }
    }

    public void showX()
    {
        Console.WriteLine("X=" + X);
    }
}
class Program
{
    static void Main(string[] args)
    {
        MyStruct d = new MyStruct();

        d.X = 10;
        d.showX();
        Console.WriteLine("X value=" + d.X);

        MyClass c = new MyClass();
        c.X = 10;

        Console.WriteLine("struct.X = {0}, class.X = {1}", d.X, c.X);
        setX(d, c);
        Console.WriteLine("struct.X = {0}, class.X = {1}", d.X, c.X);



        return;
    }

    static void setX(MyStruct s, MyClass c)
    {
        Console.WriteLine("setX()");
        s.X = 100;
        c.X = 100;
    }
}
